@extends('teacher.base')
@section('main')
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
     <legend>材料管理</legend>
    </fieldset>
    @include('teacher.error')
    <form class="layui-form"  method="post" action="" enctype="multipart/form-data">
    {!! csrf_field() !!}
	  <div class="layui-form-item">
    <label class="layui-form-label">摘要</label>
    <div class="layui-input-block">
      <input type="text" name="title" lay-verify="required" placeholder="请输入题目名字" value="{{ $info->title }}" class="layui-input">
    </div>
  	</div>

    <div class="layui-form-item">
    <label class="layui-form-label">年级</label>
    <div class="layui-input-block">
      <select name="grade" lay-filter="aihao">
        @foreach($grades as $v)
        <option value="{{ $v->id }}" {{$v->id == $info->grade_id?'selected':''}}>{{ $v->name }}</option>
        @endforeach
      </select>
    </div>
    </div>

	<div class="layui-form-item">
    <label class="layui-form-label">科目</label>
    <div class="layui-input-block">
      <select name="subject" lay-filter="aihao">
        @foreach($subjects as $v)
        <option value="{{ $v->id }}" {{$v->id == $info->subject_id?'selected':''}}>{{ $v->name }}</option>
        @endforeach
      </select>
    </div>
    </div>

    <div class="layui-form-item">
    <label class="layui-form-label">材料</label>
    <div class="layui-input-block">
      <div id="editor">
        
      </div>
      <textarea id="text1" style="width:100%; height:200px;display: none;" name="content"></textarea>
    </div>
    </div>



 
<script type="text/html" id="barDemo">
  <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">按钮1</a>
  <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="edit">按钮2</a>
</script>
  <div class="layui-form-item">
    <div class="layui-input-block">
      <button class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>
      <button type="reset" class="layui-btn layui-btn-primary">重置</button>
    </div>
  </div>
    </form>

    <div class="layui-form-item">

    <form action="{{asset('Teacher/material/bind\/').$info->id}}" method="post">
    <div class="layui-form-item">
    <label class="layui-form-label">题目绑定{{$info->id}}</label>
    <div class="layui-input-inline">
        <input type="text" name="material" lay-verify="required|number"  autocomplete="off" class="layui-input" placeholder="请输入id号">
      </div>
      <div class="layui-input-inline">
        {!! csrf_field() !!}
        <button class="layui-btn layui-btn-normal layui-btn-xs" ><i class="layui-icon">&#xe615;</i>绑定</button>
      </div>
    </div>
    </form>

    <div class="layui-form-item">

    <label class="layui-form-label">材料题目</label>
    <div class="layui-input-block">
      <table class="layui-table">
        <thead>
          <tr>
            <th>题目</th>
            <th style="width: 200px;">操作</th>
          </tr>
          @foreach($info->getQuestion as $v)
          <tr>
            <td>{{ $v->title }}</td>
            <td>
              <button class="layui-btn layui-btn-xs layui-btn-primary">
                查看
              </button>
              <button class="layui-btn layui-btn-xs layui-btn-danger" onclick="del({{$v->id}},this)">
                <i class="layui-icon">&#xe640;</i>
              </button>
            </td>
          </tr>
          @endforeach
        </thead>
      </table>
    </div>
    </div>


<script type="text/javascript" src="{{asset('wangEditor.min.js')}}"></script>
<script type="text/javascript">
    var E = window.wangEditor
    var editor = new E('#editor')
    var $text1 = $('#text1')
    editor.customConfig.onchange = function (html) {
            // 监控变化，同步更新到 textarea
            $text1.val(html);
    }
    editor.create();
    $text1.val(editor.txt.html('{!! $info->content !!}'));
</script>
<script>

layui.use(['form', 'layer','element'], function(){
  var form = layui.form
  ,$ = layui.jquery
  ,element = layui.element
  ,layer = layui.layer;
	
form.on('radio(filter)', function(data){
  if(data.value==1){
	$('#chose_html').html(chose_html);
  $('#answer').show();
  }else if(data.value==2){
	$('#chose_html').html(chose_html2);
  $('#answer').hide();

  }else if(data.value==3){
  $('#chose_html').html(chose_html3);
  $('#answer').show();

  }
  console.log(data.elem); //得到radio原始DOM对象
  console.log(data.value); //被点击的radio的value值
});  



});


function del(a,b){
  $(b).parents("tr").html(''); // 清除html
  $.post('/Teacher/material/del_question',{id:a,_token:'{{csrf_token()}}'},function(data,status){
    if(status=='success'){
      layer.msg('成功删除！');
    }
  });
  console.log(a);
}
</script>

@endsection
